import promise from './promise.js'
console.log(promise,"prodmise")
let showModal = promise.uniPromise(uni.showModal, true);

/**
 * 全局消息的成功提示
 * @param {string} -msg 需要传入的提示信息
 */
const success = (msg) => {
	let t = setTimeout(() => {
		uni.showToast({
			title: msg,
			icon: 'success',
			duration: 2000
		})
		clearTimeout(t)
	}, 0);
}

/**
 * 全局提示（包括错误提示，信息提示，警告提示）
 * @param {string} -msg 需要传入的提示信息
 */
const tip = (msg) => {
	let t = setTimeout(() => {
		uni.showToast({
			title: msg || "",
			icon: 'none',
			duration: 2000
		})
		clearTimeout(t)
	}, 0);
}
//隐藏消息提示框
const hideTip = (msg) => {
	uni.hideToast();
}

/**
 *正在加载中
 */
const loading = (msg) => {
	uni.showLoading({
		title: msg || '正在加载中...',
		mask: true
	})
}

/**
 * 关闭加载
 */
const hideLoading = () => {
	uni.hideLoading();
}

/**
 * 弹窗提示
 * @param {object} -obj 小程序弹窗封装
 */
const modal = (obj) => {

	return showModal({
		title: obj.title, // 弹窗标题
		content: obj.content, // 弹窗内容
		showCancel: obj.isCancel || false, //是否显示取消按钮，不填或者 'false' 则不显示
		cancelText: obj.cancelText || "取消", //取消文本， 默认为 ‘取消’
		confirmText: obj.confirmText || "确定", //确定文本 默认为 ‘确定’
	})
}

export default {
	success: success,
	tip: tip,
	hideTip: hideTip,
	modal: modal,
	loading: loading,
	hideLoading: hideLoading
}
